package com.easylinkin.linkappapi.openapi.dto.systemDock;

import com.alibaba.fastjson.JSONObject;
import com.easylinkin.linkappapi.openapi.util.Base64Util;
import com.easylinkin.linkappapi.openapi.util.HttpClientUtil;
import com.easylinkin.linkappapi.openapi.util.MD5Util;
import com.google.api.client.repackaged.com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import lombok.Data;

import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 实名制信息上传对接实体映射DTO
 */
@Data
public class RealNameSystemDTO {

    //特种作业证件照列表(Base64列表)
    private List certificatePhotoList;

    //所属企业
    private String company;

    //劳动合同(Base64列表)
    private List contract;

    private String headImage;

    private String idNum;

    //删除状态(0 未删除1 已删除
    private Integer isDelet;

    private String name;

    private String phone;

    private String projectName;

    private String sectionName;

    //性别:1,男,2,女
    private Integer sex;
    private String team;
    //培训状态:1已培训;0未培训
    private Integer trainingStatus;
    private Integer workStatus;
    private String workType;

    private String entryTime;

    private String departureTime;


    public static void main(String[] args) throws NoSuchFieldException {

        RealNameSystemDTO dto = new RealNameSystemDTO();
        dto.setIdNum("42022219950504143X");
        dto.setProjectName("cookie测试项目");
        dto.setSectionName("cookie测试标段");
        dto.setWorkType("特殊工种");
        dto.setCompany("test");
        dto.setEntryTime("2022-03-03");

        String img = "http://jg-linkthings.oss-cn-hangzhou.aliyuncs.com/public/aep/test/picture/jiangong/202212061101005-方玲photo.png";
        //img="https://oss-cn-hangzhou.aliyuncs.com/public/aep/dev/document/20230601163817-测试空白PDF.pdf";
        img="http://jg-linkthings.oss-cn-hangzhou.aliyuncs.com/public/nb/prod/OverallPic_1624359833401028610_2023-06-05%2010%3A52%3A31" +
               "?Expires=1717469568&OSSAccessKeyId=LTAI5tPo4WdYmq1irwtLciAr&Signature" +
              "=0sqPL69e4VsjWsGHgIwNV%2B5tiHY%3D";
        //img="http://58.49.79.249:19000/linkthings/OverallPic_421004198709050832_2022-11-10 21:06:09";
        String str = Base64Util.getImgStrToBase64(img);
        // dto.setHeadImage(str);

//        map.put("idNum", "42022219950504143X");
//        map.put("projectName", "cookie测试项目");
//        map.put("sectionName", "cookie测试标段");
//        map.put("workType", "特殊工种");
//        map.put("company", "test");
//        String join = Joiner.on("&").withKeyValueSeparator("=").join(map);

//        System.out.println(join);

        String json = JSONObject.toJSONString(dto);
//        System.out.println(json);
//        String seedStr = join + "&key=" + MD5Util.getMD5("whzh5489sw1");
//        System.out.println("seedStr:" + seedStr);
        //对sendstr进行MD5加密
//        String sign = MD5Util.getMD5(seedStr).toUpperCase();

//        System.out.println("sign:" + sign);

        String url = "https://syyzw.szridge.com:9289/assessHardware/rjStaffInfo/saveOrUpdateStaffInfo";

        String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWJJZCI6IjE1ODQ3NTI5MTA3NDU0Njg5MzAiLCJ0b2tlbl90eXBlIjoiQXV0aG9yaXphdGlvbiIsImV4cCI6MTY4NTYxODQ4NiwiY3JlYXRlZCI6MTY4NTYxMTI4NjE4MCwiY2xpZW50X2lkIjoiZWFzdFdlc3RMYWtlMSJ9.o9yaJ_wkL7j2kH7aPLGGnuA7aqE8M-2JRkMX77M7U9JQFh9Wj0m3VL9_cJMqiZgTNG1MwsEvjgWzq-cpGWbYRQ";
        token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWJJZCI6IjE1ODQ3NTI5MTA3NDU0Njg5MzAiLCJ0b2tlbl90eXBlIjoiQXV0aG9yaXphdGlvbiIsImV4cCI6MTY4NTk0ODM5OCwiY3JlYXRlZCI6MTY4NTk0MTE5ODM5NCwiY2xpZW50X2lkIjoiZWFzdFdlc3RMYWtlMSJ9.iNCviBKBSoRVsSIuhPIhau6Emt0pWLq4v9Vbhv72Q_8X76igvkgUBHTnG8XiJQadVcBYurfA3yB9iHWXvJ1jHg";
        json = "[" + json + "]";
        String s = HttpClientUtil.doPostToken(url, json, token);
        System.out.println(s);
        System.out.println(json);
    }

    public static int fileExists(String path) {
        File file = new File(path);
        System.out.println(path);
        if (file.isFile())
            return 1; // 是文件
        else if (file.isDirectory()) {
            if (file.list().length > 0)
                return 2;   // 非空文件夹
            else
                return 3;   // 空文件夹
        }
        return 0; // 路径不存在
    }
}
